Shader "Level4/UV/UVScale" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_Min("Min",float) = 0.3
		_Max("Max",float) = 0.6
		_Multi("Multi",float) = 1
	}
	
	CGINCLUDE
		#include "UnityCG.cginc"
		sampler2D _MainTex;
		float _Min;
		float _Max;
		float _Multi;
		struct v2f{
			float4 pos:POSITION;
			float2 uv:TEXCOORD;
		};
		
		v2f vert(appdata_full p):POSITION{
			v2f v;
			v.pos = mul(UNITY_MATRIX_MVP,p.vertex);
			v.uv = p.texcoord;
			
			return v;
		}
		
		float4 frag(v2f v):COLOR{
			_Min = clamp(_Min / _Multi,0,1);
			_Max = clamp(_Max / _Multi,0,1);
			float4 c = tex2D(_MainTex,v.uv);
			if(v.uv.x < _Min || v.uv.y < _Min){
				c.a = 0;
			}
			if(v.uv.x > _Max || v.uv.y > _Max){
				c.a = 0;
			}
			if(v.uv.x >= _Min && v.uv.y <= _Max){
				//将[x,y]映射到[0,1]
				v.uv = ( v.uv - _Min ) / _Min ;
				c.rgb = tex2D(_MainTex,v.uv);
			}
			return c;
		}
	
	ENDCG
	
	SubShader {
		Tags {"Queue"="Transparent" }
		LOD 200
		Blend SrcAlpha OneMinusSrcAlpha
		
		Pass{
			CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag
			ENDCG
		}
	}
	FallBack "Diffuse"
}
